import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'position',
    component: () => import(/* webpackChunkName: "position" */ '../views/position'),
    beforeEnter: (to, from, next) => {
        let positionData = localStorage.getItem('positionData');
        if(positionData){
            next('/main')
        }else{
            next()
        }
    }
  },
  {
      path:'/main',
      component: () => import(/* webpackChunkName: "main" */ '../views/main'),
      children:[
          {
              path:'/main/home',
              component: () => import(/* webpackChunkName: "main" */ '../views/main/home'),
          },
          {
              path:'/main',
              redirect:'/main/home'
          }
      ]
  },
  {
      path:'/setPos',
      component: () => import(/* webpackChunkName: "main" */ '../views/setPos')
  },
  {
      path:'/detail',
      component: () => import(/* webpackChunkName: "main" */ '../views/detail')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
